#line 1 "D:/Mikroelektronika/mikroC PRO for AVR/Examples/BTCommunication.c"
void USART_Send8(unsigned char u8Data) {

 while (!(UCSRA & (1 << UDRE)));

 UDR = u8Data;
}

const char _THRESHOLD = 20;
char counter = 0;
char ispis = 0;

void Timer0Overflow_ISR() org IVT_ADDR_TIMER0_OVF {

 if (counter >= _THRESHOLD) {
 if((ispis % 2) != 0){
 USART_Send8((rand()%60)+40);
 }
 ispis++;
 counter = 0;
 }
 else
 counter++;

}

void main() {
 char uart_rd;
 int i = 0;
 srand(1121);
 UART1_Init(9600);
 Delay_ms(100);
 UART1_Write(0x02);
 UART1_Write(0x52);
 UART1_Write(0x04);
 UART1_Write(0x0A);
 UART1_Write(0x00);
 UART1_Write(0x60);

 UART1_Write(0x09);
 UART1_Write(0x4D);
 UART1_Write(0x49);
 UART1_Write(0x4E);
 UART1_Write(0x4F);
 UART1_Write(0x54);
 UART1_Write(0x41);
 UART1_Write(0x55);
 UART1_Write(0x52);
 UART1_Write(0x00);
 UART1_Write(0x03);

 Delay_ms(100);

 UART1_Write(0x02);
 UART1_Write(0x52);
 UART1_Write(0x4E);
 UART1_Write(0x01);
 UART1_Write(0x00);
 UART1_Write(0xA1);
 UART1_Write(0x03);
 UART1_Write(0x03);
 Delay_ms(100);

 SREG_I_bit = 1;
 TOIE0_bit = 1;
 TCCR0 = 5;
 while(1){
 }
}
